<%@ page language="java" pageEncoding="UTF-8"%>
<%@ page import="dj.pageModel.PcompanyReport" %>
<script type="text/javascript">
	function addCompanyTask() {
		$('<div/>').dialog({
			href : '${pageContext.request.contextPath}/app/company/datareport/task/company_task_create.jsp',
			width : 830,
			height : 120,
			modal : true,
			title : '添加用户',
			buttons : [ {
				text : '添加',
				iconCls : 'icon-add',
				handler : function() {
					var d = $(this).closest('.window-body');
					$.ajax({
						type : "POST",
						url : "${pageContext.request.contextPath}/companyReportAction!createReportTask.action",
						data : $("#company-datareport-task-create").serialize(),
						dataType : "json",
						beforeSend : function() {
							var isValid = $("#company-datareport-task-create").form('validate');
							if (isValid) {
								$.messager.progress({
									text : "提交数据，请等待..."
								});
							}
							return isValid;
						},
						error : function(info) {
							$.messager.progress('close');
							eval(info.responseText);
						},
						success : function(result) {
							$.messager.show({
								msg : result.msg,
								title : '提示'
							});
							$.messager.progress('close');
							if(result.success) {
								$('#company-datareport-task-list-dg').datagrid('reload');
								d.dialog('destroy');
							}
						}
					});
				}
			} ],
			onClose : function() {
				$(this).dialog('destroy');
			}
		});
	}

	function editTaskDate(index) {
		$('#company-datareport-task-list-dg').datagrid('selectRow', index);
		var node = $('#company-datareport-task-list-dg').datagrid('getSelected');
		if(node) {
			$('<div/>').dialog({
				href : '${pageContext.request.contextPath}/app/company/datareport/task/editTaskDate.jsp',
				width : 420,
				height : 120,
				modal : true,
				title : '修改用户',
				buttons : [ {
					text : '保存',
					iconCls : 'icon-save',
					handler : function() {
						var d = $(this).closest('.window-body');
						$.ajax({
							type : "POST",
							url : "${pageContext.request.contextPath}/companyReportAction!updateCompanyTaskDate.action",
							dataType : "json",
							beforeSend : function() {
								var isValid = $("#company-datareport-task-edit").form('validate');
								if (isValid) {
									$.messager.progress({
										text : "提交数据，请等待..."
									});
								}
								return isValid;
							},
							data : $("#company-datareport-task-edit").serialize() + "&id=" + node.id,
							error : function(info) {
								$.messager.progress('close');
								eval(info.responseText);
							},
							success : function(result) {
								$.messager.show({
									msg : result.msg,
									title : '提示'
								});
								$.messager.progress('close');
								if(result.success) {
									$('#company-datareport-task-list-dg').datagrid('reload');
									d.dialog('destroy');
								}
							}
						});
					}
				} ],
				onLoad : function() {
					$('#company-task-edit-startDate').val(node.startDate);
					$('#company-task-edit-endDate').val(node.endDate);
					selMonth = node.taskmonth;
				},
				onClose : function() {
					$(this).dialog('destroy');
				}
			});
		} else {
			$.messager.alert('提示','没有可编辑的对象！'); 
		}
	}

	function deleteCompanyTask() {
		var nodes = $("#company-datareport-task-list-dg").datagrid("getChecked");
		if(nodes && nodes.length > 0) {
			$.messager.confirm('提示', "您确定要删除所选的任务？", function(r) {
				if (r) {
					var ids = '';
					for(var i = 0; i < nodes.length; i++) {
						ids += ',' + nodes[i].id;
					}
					if(ids.length > 1) {
						ids = ids.substring(1);
					}
					$.ajax({
						type : "post",
						dataType : "json",
						url : "${pageContext.request.contextPath}/companyReportAction!deleteCompanyTask.action",
						data : "ids=" + ids,
						error : function(info) {
							$.messager.show({
								msg : '提交信息失败！',
								title : '提示'
							});
							eval(info.responseText);
						},
						success : function(result) {
							$.messager.show({
								msg : result.msg,
								title : '提示'
							});
							$.messager.progress('close');
							if(result.success) {
								$('#company-datareport-task-list-dg').datagrid('reload');
							}
						}
					});
				}
			});
		} else {
			$.messager.alert('提示','请选择要删除的记录！'); 
		}
	}

	//查询功能
	function searchCompanyTask() {
		$("#company-datareport-task-list-dg").datagrid("options").queryParams = getQueryParams("company-datareport-task-search");
		autoLoad($("#company-datareport-task-list-dg").datagrid("getPager"), 1);
	}

	$(function() {
		$('#company-datareport-task-list-dg').datagrid({
			url : "${pageContext.request.contextPath }/companyReportAction!getReportTask.action",
			onLoadError : function(retValue) {
				eval(retValue.responseText);
			},
			singleSelect : true,
			selectOnCheck : true,
			pagination : true,
			fitColumns : true,
			pageSize : 10,
			pageList : [ 5, 10, 15, 20 ],
			nowrap : true,
			border : false,
			singleSelect : false,
			idField : 'id',
			toolbar : [ {
				text : '创建任务',
				iconCls : 'icon-add',
				handler : function() {
					addCompanyTask();
				}
			}, {
				text : '删除任务',
				iconCls : 'icon-cancel',
				handler : function() {
					deleteCompanyTask();
				}
			} ],
			frozenColumns : [ [ {
				field : 'id',
				width : 50,
				checkbox : true
			} ] ],
			columns : [ [ {
				field : 'username',
				title : '企业',
				width : 200
			}, {
				field : 'taskmonth',
				title : '月份',
				width : 100
			}, {
				field : 'startDate',
				title : '开始日期',
				width : 120
			}, {
				field : 'endDate',
				title : '结束日期',
				width : 120
			}, {
				field : 'status',
				title : '当前状态',
				width : 80,
				formatter : function(value) {
					if(value == '<%=PcompanyReport.STRUTS_未填写 %>') {
						return "未填写";
					}
					if(value == '<%=PcompanyReport.STRUTS_未提交 %>') {
						return "未提交";
					}
					if(value == '<%=PcompanyReport.STRUTS_未通过 %>') {
						return "未通过";
					}
					if(value == '<%=PcompanyReport.STRUTS_已通过 %>') {
						return "已通过";
					}
					if(value == '<%=PcompanyReport.STRUTS_未审核 %>') {
						return "未审核";
					}
				}
			}, {
				field : 'operate',
				title : '操作',
				width : 80,
				align : 'center',
				formatter : function(value, rowData, rowIndex) {
					if('<%=PcompanyReport.STRUTS_未填写%>' == rowData.status) {
						return "<a href='javascript:void(0)' onclick='editTaskDate(" + rowIndex + ");'><img src='${pageContext.request.contextPath }/images/pencil.png' oncl border='0'></a>";
					} else {
						return "--";
					}
				}
			} ] ],
			onSelect : function(rowIndex, rowData) {
				if('<%=PcompanyReport.STRUTS_未填写%>' != rowData.status) {
					$(this).datagrid('unselectRow', rowIndex);  
					$.messager.show({
						msg : '此行为非编辑状态，无法进行选择！',
						title : '提示'
					});
				}
			}, 
			onCheck : function(rowIndex, rowData) {
				if('<%=PcompanyReport.STRUTS_未填写%>' != rowData.status) {
					$.messager.show({
						msg : '此行为非编辑状态，无法进行选择！',
						title : '提示'
					});
					$(this).datagrid('uncheckRow', rowIndex);
				}
			},
			onCheckAll : function(rows) {
				if(rows && rows.length > 0) {
					for(var x = 0; x < rows.length; x++) {
						if('<%=PcompanyReport.STRUTS_未填写%>' != rows[x].status) {
							$(this).datagrid('uncheckRow', x);
						}
					}
				}
			}
		});
	});
</script>
<div class="easyui-layout" data-options="fit:true">

	<div data-options="region:'north', title:'查询', iconCls: 'icon-search'" style="height:80px; padding: 0;">
		<div style="padding-top: 10px; padding-left: 20px">
			<form id="company-datareport-task-search">
				<span>企业名称：<input type="text" id="company-datareport-task-company" name="username"></span>&nbsp;&nbsp; 
				<span>月份：<input type="text" id="company-datareport-task-month" name="taskmonth" onclick="WdatePicker({dateFmt:'yyyy-MM', minDate:'%y-%M'})"></span>&nbsp;&nbsp; 
				<span><a href="javascript:void(0)" class="easyui-linkbutton" onclick="searchCompanyTask()" data-options="iconCls:'icon-search'">查询</a></span>
			</form>
		</div>
	</div>

	<div data-options="region:'center', title:'任务列表', iconCls: 'icon-group'" style="padding: 0;">
		<table id="company-datareport-task-list-dg"></table>
	</div>

</div>
